class Solution {
    public int search(int[] nums, int target) {
        int l = -1, r = nums.length;
        int mid;
        while (l + 1 < r) {
            mid = l+(r-l)/2;
            if(nums[mid] <= target)l = mid;
            else r = mid;
        }
        return (l>=0 && nums[l] == target)?l:-1;
    }
}